<template>
	<view class="merchant">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				新商户入驻
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="nr clearfix">
				<view class="list">
					<image :src="baseUrl + '/wximage/wancheng.png'"></image>
					<view class="title">新增商户</view>
				</view>
				<view class="list">
					<image :src="baseUrl + '/wximage/wancheng.png'"></image>
					<view class="title">新建门店</view>
				</view>
				<view class="list">
					<image :src="baseUrl + '/wximage/wancheng.png'"></image>
					<view class="title">开通分成</view>
				</view>
				<view class="list">
					<image :src="baseUrl + '/wximage/shiyuan.png'"></image>
					<view class="shuzi">4</view>
					<view class="title">设备安装</view>
				</view>
				<view class="list">
					<image :src="baseUrl + '/wximage/kongyuan.png'"></image>
					<view class="shuzi">5</view>
					<view class="title">完成新增</view>
				</view>
			</view>
		</view>
		<view class="anzhuang" @click="scanCode()">
			<image :src="baseUrl + '/wximage/saomaanzhuang.png'" class="bj"></image>
			<view class="name">扫码安装</view>
		</view>
		<!-- <view class="footer">
			<view class="submit" @click="submit">下一步</view>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			console.log(uni.getStorageSync('stores_id'));
		},
		methods: {
			scanCode(){
				uni.scanCode({
					scanType:['qrCode'],
					success: (res) => {
						if(res.result){
							let url = res.result;

							let qrcodeurl = getApp().globalData.baseUrl;
							
								
								if(url.indexOf('/scan') > -1){
									var arrUrl = url.split('qrcodenumber=');
									// console.log(arrUrl[1]);
									var qrcode = arrUrl[1];
									var formData = {
										'station_id': uni.getStorageSync('stores_id'),
										'bussiness_id': uni.getStorageSync('bussiness_id'),
										'qrcode': qrcode,
										'agentid': uni.getStorageSync('agent_id')
									}
									
									//请求接口绑定该商户
									this.request({
										url: '/xcxlogin/bindbussiness',
										data: formData,
										method: "POST"
									}).then(res => {
										console.log(res);
										if (res.data.code == 200) {
											// var stores_id = res.data.data.id;//用户id
											
											uni.showToast({
												title: '绑定成功',
												icon: 'none'
											});
											
											uni.setStorageSync('bussiness_ruzhu',5);
											// uni.redirectTo({
											// 	url: '/subpackageA/merchant/device'
											// })
											// idm:'',
											// idk:'',
											// uni.setStorageSync('stores_id',stores_id);
											uni.redirectTo({
												url: '/subpackageA/merchant/success'
											})
											// 	console.log('查看返回值');
											// 	console.log(res);
											// 	var userId = res.data.data.id;//用户id
											// 	uni.redirectTo({
											// 		url: '/subpackageA/merchant/store?userid='+userId
											// 	})
												
										} else {
											uni.showToast({
												title: res.data.message,
												icon: 'none'
											});
											
											
											// uni.redirectTo({
											// 	url: '/subpackageA/merchant/success'
											// })
										}
									})
									
									
									
								}
								// console.log("完成了");
								
							// }
							// return false;
							// if (url.substring(0, (qrcodeurl.length + 17)) == qrcodeurl + '/Lease?o=l5dr&&t=') {//充电宝
								//https://qrcode.w-dian.cn/Lease?o=l5dr&&t=WD061911211193
									// let qrcode = url.substring(qrcodeurl.length + 17)
									// result = { oid: 115, type: 'cab', qrcode: qrcode }
							// }
							
						}
						
					},
					fail: (res) => {
						console.log("未识别到二维码");
					}
				})
			},
			submit(){
				uni.redirectTo({
					url: '/subpackageA/merchant/success'
				})
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.merchant {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;		
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			
			.nr{
				width: 94%;
				margin: 0 auto;
				box-shadow:rgba(223, 230, 255, 0.67) 0px 0px 6px;
				border-radius: 20rpx;
				background: #FFFFFF;
				position: relative;
				
				.list{
					width: 20%;
					float: left;
					text-align: center;
					position: relative;
					
					image{
						width: 64rpx;
						height: 64rpx;
						margin-top: 26rpx;
					}
					
					.shuzi{
						font-size: 32rpx;
						color: #FFFFFF;
						font-weight: 700;
						position: absolute;
						top: 36rpx;
						left: 62rpx;
					}
					
					.title{
						font-size: 24rpx;
						color: #333333;
						margin-bottom: 26rpx;
						font-weight: 700;
					}
				}
				
				.hengxian{
					position: absolute;
					width: 490rpx;
					height: 2rpx;
					background: #C5C5C5;
					left: 110rpx;
					top: 56rpx;
				}
			}
		}
		
		.anzhuang{
			width: 94%;
			margin: 0 auto;
			margin-top: -100rpx;
			text-align: center;
			position: relative;
			
			.bj{
				width: 382rpx;
				height: 260rpx;
			}
			
			.name{
				position: absolute;
				width: 100%;
				left: 0;
				top: 176rpx;
				text-align: center;
				font-size: 28rpx;
				color: #333333;
				font-weight: 700;
			}
		}
		
		.footer{
			width: 100%;
			margin: 0 auto 40rpx;
			margin-top: 60rpx;
			height: 72rpx;
			text-align: center;
			
			.submit{
				width: 240rpx;
				height: 72rpx;
				line-height: 72rpx;
				background: linear-gradient(90deg, #65bdfc, #398ef8);
				margin-left: 248rpx;
				border-radius: 36rpx;
				border-top-left-radius: 0;
				border-bottom-left-radius: 42rpx;
				color: #FFFFFF;
				font-size: 32rpx;
			}
		}
	}
</style>